package snippet;
import java.io.*;
import java.util.*;
public class _01背包2 {
	public static void main(String[] args) throws IOException {
		int N = 5010;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
		int m = Integer.parseInt(st.nextToken());
		
		int w[] = new int[N];
		int v[] = new int[N];
		
		st = new StringTokenizer(br.readLine());
		for(int i = 1; i <= n ; i++) {
			w[i] = Integer.parseInt(st.nextToken());
		}
		st = new StringTokenizer(br.readLine());
		for(int i = 1; i <= n; i++) {
			v[i] = Integer.parseInt(st.nextToken());
		}
		
		int dp[] = new int[m+1];
		for(int i = 1; i <= n; i++) {
			for(int j = m; j >= w[i]; j--) {
				dp[j] = Math.max(dp[j], dp[j-w[i]] + v[i]);
			}
		}
		System.out.println(dp[m]);
	}
}
